﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MedicViet.Models;

namespace MedicViet.Controllers
{ 
    public class DangKyDichVuController : Controller
    {
        private MedicVietEntities db = new MedicVietEntities();

        //
        // GET: /DangKyDichVu/

        public ViewResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(ServicesRegister sv)
        {
            if (ModelState.IsValid)
            {
                db.ServicesRegisters.AddObject(sv);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(sv);
        }

        //
        // GET: /DangKyDichVu/Details/5

        public ViewResult Details(int id)
        {
            ServicesRegister servicesregister = db.ServicesRegisters.Single(s => s.id == id);
            return View(servicesregister);
        }

        //
        // GET: /DangKyDichVu/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /DangKyDichVu/Create

        [HttpPost]
        public ActionResult Create(ServicesRegister servicesregister)
        {
            if (ModelState.IsValid)
            {
                db.ServicesRegisters.AddObject(servicesregister);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(servicesregister);
        }
        
        //
        // GET: /DangKyDichVu/Edit/5
 
        public ActionResult Edit(int id)
        {
            ServicesRegister servicesregister = db.ServicesRegisters.Single(s => s.id == id);
            return View(servicesregister);
        }

        //
        // POST: /DangKyDichVu/Edit/5

        [HttpPost]
        public ActionResult Edit(ServicesRegister servicesregister)
        {
            if (ModelState.IsValid)
            {
                db.ServicesRegisters.Attach(servicesregister);
                db.ObjectStateManager.ChangeObjectState(servicesregister, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(servicesregister);
        }

        //
        // GET: /DangKyDichVu/Delete/5
 
        public ActionResult Delete(int id)
        {
            ServicesRegister servicesregister = db.ServicesRegisters.Single(s => s.id == id);
            return View(servicesregister);
        }

        //
        // POST: /DangKyDichVu/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            ServicesRegister servicesregister = db.ServicesRegisters.Single(s => s.id == id);
            db.ServicesRegisters.DeleteObject(servicesregister);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}